﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AnguaRPGEngine.Library.Interfaces;
using System.Windows.Forms;
using System.Drawing;
using AnguaRPGEngine.Library.Parts;
using System.IO;

namespace AnguaRPGEngine.DND4eModule
{
    #region Alignments
    public enum Alignments
    {
        Chaotic_Evil,
        Evil,
        Good,
        Lawful_Good,
        Unaligned
    }
    #endregion
    #region Dieties
    public enum Dieties
    {
        Abbathor,
        Akadi,
        Amounator,
        Angharradh,
        Arawai,
        Aruoreen,
        Asmodeus,
        Aureon,
        Auril,
        Aurom,
        Avandra,
        Baalzebul,
        Baeruan_Wildwanderer,
        Bahamut,
        Bahgtru,
        Balinor,
        Bane,
        Baravar_Cloakshadow,
        Bazim__Gorag,
        Bel,
        Belial,
        Berronar_Truesilver,
        Beshaba,
        Boldrei,
        Brandobaris,
        Callarduran_Smoothhands,
        Chauntea,
        Clangeddin_Silverbeard,
        Corellon,
        Cults_of_the_Dragon_Below,
        Cyric,
        Cyrrollalee,
        Deep_Sashelas,
        Dispater,
        Dol_Arrah,
        Dugmaren_Brightmantle,
        Elf_Religion,
        Erathis,
        Erevan_Ilesere,
        Fenmarel_Mestarine,
        Fzoul_Chembryl,
        Garagos,
        Garl_Glittergold,
        Ghaunadaur,
        Glasya,
        Gond,
        Grumbar,
        Gruumsh,
        Haramathur,
        Hoar,
        Hruggek,
        Ilmater,
        Ioun,
        Istishia,
        Jergal,
        Kelemour,
        Kol_Korran,
        Kord,
        Kossuth,
        Labelas_Enoreth,
        Lareis,
        Levistus,
        Lliira,
        Lolth,
        Loviatar,
        Luthic,
        Maglubiyet,
        Malar,
        Mammon,
        Morthammor_Duin,
        Melora,
        Mephistopheles,
        Mielikke,
        Milil,
        Moradin,
        Nusemnee,
        Obould,
        Oghma,
        Olladra,
        Onatar,
        Pelor,
        Sagawehn,
        Sehanine,
        Selune,
        Shar,
        Sharess,
        Shargaas,
        Sheela_Peryroyl,
        Shevarash,
        Shiallia,
        Siamorphe,
        Silvanus,
        Solonor,
        Thelandira,
        Sseth,
        Sune,
        Talona,
        Tempus,
        Thard_Horr,
        Tharizdun,
        The_Blood_of_Vol,
        The_Dark_Six,
        The_Devourer,
        The_Fury,
        The_Keeper,
        The_Mockery,
        The_Path_of_Light,
        The_Raven_Queen,
        The_Red_Knight,
        The_Shadow,
        The_Silver_Flame,
        The_Sovereign_Host,
        The_Spirits_of_the_Past,
        The_Traveler,
        The_Undying_Court,
        Tiamat,
        Torm,
        Torog,
        Tymora,
        Umberlee,
        Uthgar,
        Valkur,
        Vaprak,
        Vecna,
        Vergadain,
        Waukeen,
        Zehir
    }
    #endregion
     public class DNDPlayerCharacter
    {
        public Guid ID;
        public string CharacterName;
        public CharacterClass CharacterClass;
        public string ParagonPath;
        public string EpicDestiny;
        public string PlayerName;
        public Guid PlayerID;
        public CharacterRace CharacterRace;
        public string Size;
        public int Age;
        public string Gender;
        public string Height;
        public string Weight;
        public Alignments Alignment;
        public Dieties Diety;
        public string AdventuringCompanyOrOtherAffiliations;
        public int XP;
        public int Speed;
        public int HitPoints;
        public Point Location;
        public int Rotation;
        public string ImageName;
        public int PassiveInsight
        {
            get
            {
                return 0;
            }
        }
        public int PassivePerception
        {
            get
            {
                return 0;
            }
        }
        public string AdditionalEffects;
       
        public int Level
        {
            get
            {
                if (XP >= 1000000) return 30;
                if (XP >= 825000) return 29;
                if (XP >= 675000) return 28;
                if (XP >= 550000) return 27;
                if (XP >= 450000) return 26;
                if (XP >= 375000) return 25;
                if (XP >= 310000) return 24;
                if (XP >= 255000) return 23;
                if (XP >= 210000) return 22;
                if (XP >= 175000) return 21;
                if (XP >= 143000) return 20;
                if (XP >= 119000) return 19;
                if (XP >= 99000) return 18;
                if (XP >= 83000) return 17;
                if (XP >= 69000) return 16;
                if (XP >= 57000) return 15;
                if (XP >= 47000) return 14;
                if (XP >= 39000) return 13;
                if (XP >= 32000) return 12;
                if (XP >= 26000) return 11;
                if (XP >= 20500) return 10;
                if (XP >= 16500) return 9;
                if (XP >= 13000) return 8;
                if (XP >= 10000) return 7;
                if (XP >= 7500) return 6;
                if (XP >= 5500) return 5;
                if (XP >= 3750) return 4;
                if (XP >= 2250) return 3;
                if (XP >= 1000) return 2;
                return 1;
            }
        }
        public int Initiative
        {
            get
            {
                return Dexterity.ModPlusOneHalfLevel(Level) + InitiativeMiscMod;
            }
        }
        public int InitiativeMiscMod;
        public string InitiativeConditionalMods;
        public AbilityScore Strength;
        public AbilityScore Constitution;
        public AbilityScore Dexterity;
        public AbilityScore Intelligence;
        public AbilityScore Wisdom;
        public AbilityScore Charisma;
        public Skill Acrobatics;
        public Skill Arcana;
        public Skill Athletics;
        public Skill Bluff;
        public Skill Diplomacy;
        public Skill Dungeoneering;
        public Skill Endurance;
        public Skill Heal;
        public Skill History;
        public Skill Insight;
        public Skill Intimidate;
        public Skill Nature;
        public Skill Perception;
        public Skill Religion;
        public Skill Stealth;
        public Skill Streetwise;
        public Skill Thievery;
        public Defense ArmorClass;
        public Defense Fortitude;
        public Defense Reflex;
        public Defense Will;
        public void Initialize()
        {
            if (Strength == null)
            {
                ResetToDefaults();
            }
            Strength.OnAbilityScoreChanged += new AbilityScore.AbilityScoreChangedEventHandler(OnAbilityScoreChanged);
            Constitution.OnAbilityScoreChanged += new AbilityScore.AbilityScoreChangedEventHandler(OnAbilityScoreChanged);
            Dexterity.OnAbilityScoreChanged += new AbilityScore.AbilityScoreChangedEventHandler(OnAbilityScoreChanged);
            Intelligence.OnAbilityScoreChanged += new AbilityScore.AbilityScoreChangedEventHandler(OnAbilityScoreChanged);
            Wisdom.OnAbilityScoreChanged += new AbilityScore.AbilityScoreChangedEventHandler(OnAbilityScoreChanged);
            Charisma.OnAbilityScoreChanged += new AbilityScore.AbilityScoreChangedEventHandler(OnAbilityScoreChanged);
        }

        void OnAbilityScoreChanged(string Name)
        {
            switch (Name)
            {
                case "Strength":
                    Athletics.ModPlusHalfLevel = Strength.ModPlusOneHalfLevel(Level);
                    break;
                case "Constitution":
                    Endurance.ModPlusHalfLevel = Constitution.ModPlusOneHalfLevel(Level);
                    break;
                case "Dexterity":
                    Acrobatics.ModPlusHalfLevel = Dexterity.ModPlusOneHalfLevel(Level);
                    Stealth.ModPlusHalfLevel = Dexterity.ModPlusOneHalfLevel(Level);
                    Thievery.ModPlusHalfLevel = Dexterity.ModPlusOneHalfLevel(Level);
                    break;
                case "Intelligence":
                    Arcana.ModPlusHalfLevel = Intelligence.ModPlusOneHalfLevel(Level);
                    History.ModPlusHalfLevel = Intelligence.ModPlusOneHalfLevel(Level);
                    Religion.ModPlusHalfLevel = Intelligence.ModPlusOneHalfLevel(Level);
                    break;
                case "Wisdom":
                    Dungeoneering.ModPlusHalfLevel = Wisdom.ModPlusOneHalfLevel(Level);
                    Heal.ModPlusHalfLevel = Wisdom.ModPlusOneHalfLevel(Level);
                    Insight.ModPlusHalfLevel = Wisdom.ModPlusOneHalfLevel(Level);
                    Nature.ModPlusHalfLevel = Wisdom.ModPlusOneHalfLevel(Level);
                    Perception.ModPlusHalfLevel = Wisdom.ModPlusOneHalfLevel(Level);
                    break;
                case "Charisma":
                    Bluff.ModPlusHalfLevel = Charisma.ModPlusOneHalfLevel(Level);
                    Diplomacy.ModPlusHalfLevel = Charisma.ModPlusOneHalfLevel(Level);
                    Intimidate.ModPlusHalfLevel = Charisma.ModPlusOneHalfLevel(Level);
                    Streetwise.ModPlusHalfLevel = Charisma.ModPlusOneHalfLevel(Level);
                    break;
            }
        }
        public void Update(DNDPlayerCharacter playerCharacter)
        {
            #region Actobatics
            this.Acrobatics.ArmorPenalty = playerCharacter.Acrobatics.ArmorPenalty;
            this.Acrobatics.Misc = playerCharacter.Acrobatics.Misc;
            this.Acrobatics.ModPlusHalfLevel = playerCharacter.Acrobatics.ModPlusHalfLevel;
            this.Acrobatics.Name = playerCharacter.Acrobatics.Name;
            this.Acrobatics.Trained = playerCharacter.Acrobatics.Trained;
            #endregion
            this.AdditionalEffects = playerCharacter.AdditionalEffects;
            this.AdventuringCompanyOrOtherAffiliations = playerCharacter.AdventuringCompanyOrOtherAffiliations;
            this.Age = playerCharacter.Age;
            this.Alignment = playerCharacter.Alignment;
            #region Arcana
            this.Arcana.ArmorPenalty = playerCharacter.Arcana.ArmorPenalty;
            this.Arcana.Misc = playerCharacter.Arcana.Misc;
            this.Arcana.ModPlusHalfLevel = playerCharacter.Arcana.ModPlusHalfLevel;
            this.Arcana.Name = playerCharacter.Arcana.Name;
            this.Arcana.Trained = playerCharacter.Arcana.Trained;
            #endregion
            #region Armor Class
            this.ArmorClass.ArmorSlashAbilityMod = playerCharacter.ArmorClass.ArmorSlashAbilityMod;
            this.ArmorClass.ClassMod = playerCharacter.ArmorClass.ClassMod;
            this.ArmorClass.ConditionalBonuses = playerCharacter.ArmorClass.ConditionalBonuses;
            this.ArmorClass.DisplayName = playerCharacter.ArmorClass.DisplayName;
            this.ArmorClass.EnhancementMod = playerCharacter.ArmorClass.EnhancementMod;
            this.ArmorClass.FeatMod = playerCharacter.ArmorClass.FeatMod;
            this.ArmorClass.HalfLevel = playerCharacter.ArmorClass.HalfLevel;
            this.ArmorClass.MiscMod = playerCharacter.ArmorClass.MiscMod;
            this.ArmorClass.MiscMod2 = playerCharacter.ArmorClass.MiscMod2;
            this.ArmorClass.Name = playerCharacter.ArmorClass.Name;
            #endregion
            #region Athletics
            this.Athletics.ArmorPenalty = playerCharacter.Athletics.ArmorPenalty;
            this.Athletics.Misc = playerCharacter.Athletics.Misc;
            this.Athletics.ModPlusHalfLevel = playerCharacter.Athletics.ModPlusHalfLevel;
            this.Athletics.Name = playerCharacter.Athletics.Name;
            this.Athletics.Trained = playerCharacter.Athletics.Trained;
            #endregion
            #region Bluff
            this.Bluff.ArmorPenalty = playerCharacter.Bluff.ArmorPenalty;
            this.Bluff.Misc = playerCharacter.Bluff.Misc;
            this.Bluff.ModPlusHalfLevel = playerCharacter.Bluff.ModPlusHalfLevel;
            this.Bluff.Name = playerCharacter.Bluff.Name;
            this.Bluff.Trained = playerCharacter.Bluff.Trained;
            #endregion
            this.CharacterClass = playerCharacter.CharacterClass;
            this.CharacterName = playerCharacter.CharacterName;
            this.CharacterRace = playerCharacter.CharacterRace;
            #region Charisma
            this.Charisma.Name = playerCharacter.Charisma.Name;
            this.Charisma.Score = playerCharacter.Charisma.Score;
            #endregion
            #region Constitution
            this.Constitution.Name = playerCharacter.Constitution.Name;
            this.Constitution.Score = playerCharacter.Constitution.Score;
            #endregion
            #region Dexterity
            this.Dexterity.Name = playerCharacter.Dexterity.Name;
            this.Dexterity.Score = playerCharacter.Dexterity.Score;
            #endregion
            this.Diety = playerCharacter.Diety;
            #region Diplomacy
            this.Diplomacy.ArmorPenalty = playerCharacter.Diplomacy.ArmorPenalty;
            this.Diplomacy.Misc = playerCharacter.Diplomacy.Misc;
            this.Diplomacy.ModPlusHalfLevel = playerCharacter.Diplomacy.ModPlusHalfLevel;
            this.Diplomacy.Name = playerCharacter.Diplomacy.Name;
            this.Diplomacy.Trained = playerCharacter.Diplomacy.Trained;
            #endregion
            #region Dungeoneering
            this.Dungeoneering.ArmorPenalty = playerCharacter.Dungeoneering.ArmorPenalty;
            this.Dungeoneering.Misc = playerCharacter.Dungeoneering.Misc;
            this.Dungeoneering.ModPlusHalfLevel = playerCharacter.Dungeoneering.ModPlusHalfLevel;
            this.Dungeoneering.Name = playerCharacter.Dungeoneering.Name;
            this.Dungeoneering.Trained = playerCharacter.Dungeoneering.Trained;
            #endregion
            #region Endurance
            this.Endurance.ArmorPenalty = playerCharacter.Endurance.ArmorPenalty;
            this.Endurance.Misc = playerCharacter.Endurance.Misc;
            this.Endurance.ModPlusHalfLevel = playerCharacter.Endurance.ModPlusHalfLevel;
            this.Endurance.Name = playerCharacter.Endurance.Name;
            this.Endurance.Trained = playerCharacter.Endurance.Trained;
            #endregion
            this.EpicDestiny = playerCharacter.EpicDestiny;
            #region Fortitude
            this.Fortitude.ArmorSlashAbilityMod = playerCharacter.Fortitude.ArmorSlashAbilityMod;
            this.Fortitude.ClassMod = playerCharacter.Fortitude.ClassMod;
            this.Fortitude.ConditionalBonuses = playerCharacter.Fortitude.ConditionalBonuses;
            this.Fortitude.DisplayName = playerCharacter.Fortitude.DisplayName;
            this.Fortitude.EnhancementMod = playerCharacter.Fortitude.EnhancementMod;
            this.Fortitude.FeatMod = playerCharacter.Fortitude.FeatMod;
            this.Fortitude.HalfLevel = playerCharacter.Fortitude.HalfLevel;
            this.Fortitude.MiscMod = playerCharacter.Fortitude.MiscMod;
            this.Fortitude.MiscMod2 = playerCharacter.Fortitude.MiscMod2;
            this.Fortitude.Name = playerCharacter.Fortitude.Name;
            #endregion
            this.Gender = playerCharacter.Gender;
            #region Heal
            this.Heal.ArmorPenalty = playerCharacter.Heal.ArmorPenalty;
            this.Heal.Misc = playerCharacter.Heal.Misc;
            this.Heal.ModPlusHalfLevel = playerCharacter.Heal.ModPlusHalfLevel;
            this.Heal.Name = playerCharacter.Heal.Name;
            this.Heal.Trained = playerCharacter.Heal.Trained;
            #endregion
            this.Height = playerCharacter.Height;
            #region History
            this.History.ArmorPenalty = playerCharacter.History.ArmorPenalty;
            this.History.Misc = playerCharacter.History.Misc;
            this.History.ModPlusHalfLevel = playerCharacter.History.ModPlusHalfLevel;
            this.History.Name = playerCharacter.History.Name;
            this.History.Trained = playerCharacter.History.Trained;
            #endregion
            this.HitPoints = playerCharacter.HitPoints;
            this.InitiativeConditionalMods = playerCharacter.InitiativeConditionalMods;
            this.InitiativeMiscMod = playerCharacter.InitiativeMiscMod;
            #region Insight
            this.Insight.ArmorPenalty = playerCharacter.Insight.ArmorPenalty;
            this.Insight.Misc = playerCharacter.Insight.Misc;
            this.Insight.ModPlusHalfLevel = playerCharacter.Insight.ModPlusHalfLevel;
            this.Insight.Name = playerCharacter.Insight.Name;
            this.Insight.Trained = playerCharacter.Insight.Trained;
            #endregion
            #region Intelligence
            this.Intelligence.Name = playerCharacter.Intelligence.Name;
            this.Intelligence.Score = playerCharacter.Intelligence.Score;
            #endregion
            #region Intimidate
            this.Intimidate.ArmorPenalty = playerCharacter.Intimidate.ArmorPenalty;
            this.Intimidate.Misc = playerCharacter.Intimidate.Misc;
            this.Intimidate.ModPlusHalfLevel = playerCharacter.Intimidate.ModPlusHalfLevel;
            this.Intimidate.Name = playerCharacter.Intimidate.Name;
            this.Intimidate.Trained = playerCharacter.Intimidate.Trained;
            #endregion
            #region Nature
            this.Nature.ArmorPenalty = playerCharacter.Nature.ArmorPenalty;
            this.Nature.Misc = playerCharacter.Nature.Misc;
            this.Nature.ModPlusHalfLevel = playerCharacter.Nature.ModPlusHalfLevel;
            this.Nature.Name = playerCharacter.Nature.Name;
            this.Nature.Trained = playerCharacter.Nature.Trained;
            #endregion
            this.ParagonPath = playerCharacter.ParagonPath;
            #region Perception
            this.Perception.ArmorPenalty = playerCharacter.Perception.ArmorPenalty;
            this.Perception.Misc = playerCharacter.Perception.Misc;
            this.Perception.ModPlusHalfLevel = playerCharacter.Perception.ModPlusHalfLevel;
            this.Perception.Name = playerCharacter.Perception.Name;
            this.Perception.Trained = playerCharacter.Perception.Trained;
            #endregion
            this.PlayerName = playerCharacter.PlayerName;
            #region Reflex
            this.Reflex.ArmorSlashAbilityMod = playerCharacter.Reflex.ArmorSlashAbilityMod;
            this.Reflex.ClassMod = playerCharacter.Reflex.ClassMod;
            this.Reflex.ConditionalBonuses = playerCharacter.Reflex.ConditionalBonuses;
            this.Reflex.DisplayName = playerCharacter.Reflex.DisplayName;
            this.Reflex.EnhancementMod = playerCharacter.Reflex.EnhancementMod;
            this.Reflex.FeatMod = playerCharacter.Reflex.FeatMod;
            this.Reflex.HalfLevel = playerCharacter.Reflex.HalfLevel;
            this.Reflex.MiscMod = playerCharacter.Reflex.MiscMod;
            this.Reflex.MiscMod2 = playerCharacter.Reflex.MiscMod2;
            this.Reflex.Name = playerCharacter.Reflex.Name;
            #endregion
            #region Religion
            this.Religion.ArmorPenalty = playerCharacter.Religion.ArmorPenalty;
            this.Religion.Misc = playerCharacter.Religion.Misc;
            this.Religion.ModPlusHalfLevel = playerCharacter.Religion.ModPlusHalfLevel;
            this.Religion.Name = playerCharacter.Religion.Name;
            this.Religion.Trained = playerCharacter.Religion.Trained;
            #endregion
            this.Size = playerCharacter.Size;
            this.Speed = playerCharacter.Speed;
            #region Stealth
            this.Stealth.ArmorPenalty = playerCharacter.Stealth.ArmorPenalty;
            this.Stealth.Misc = playerCharacter.Stealth.Misc;
            this.Stealth.ModPlusHalfLevel = playerCharacter.Stealth.ModPlusHalfLevel;
            this.Stealth.Name = playerCharacter.Stealth.Name;
            this.Stealth.Trained = playerCharacter.Stealth.Trained;
            #endregion
            #region Streetwise
            this.Streetwise.ArmorPenalty = playerCharacter.Streetwise.ArmorPenalty;
            this.Streetwise.Misc = playerCharacter.Streetwise.Misc;
            this.Streetwise.ModPlusHalfLevel = playerCharacter.Streetwise.ModPlusHalfLevel;
            this.Streetwise.Name = playerCharacter.Streetwise.Name;
            this.Streetwise.Trained = playerCharacter.Streetwise.Trained;
            #endregion
            #region Strength
            this.Strength.Name = playerCharacter.Strength.Name;
            this.Strength.Score = playerCharacter.Strength.Score;
            #endregion
            #region Thievery
            this.Thievery.ArmorPenalty = playerCharacter.Thievery.ArmorPenalty;
            this.Thievery.Misc = playerCharacter.Thievery.Misc;
            this.Thievery.ModPlusHalfLevel = playerCharacter.Thievery.ModPlusHalfLevel;
            this.Thievery.Name = playerCharacter.Thievery.Name;
            this.Thievery.Trained = playerCharacter.Thievery.Trained;
            #endregion
            this.Weight = playerCharacter.Weight;
            #region Will
            this.Will.ArmorSlashAbilityMod = playerCharacter.Will.ArmorSlashAbilityMod;
            this.Will.ClassMod = playerCharacter.Will.ClassMod;
            this.Will.ConditionalBonuses = playerCharacter.Will.ConditionalBonuses;
            this.Will.DisplayName = playerCharacter.Will.DisplayName;
            this.Will.EnhancementMod = playerCharacter.Will.EnhancementMod;
            this.Will.FeatMod = playerCharacter.Will.FeatMod;
            this.Will.HalfLevel = playerCharacter.Will.HalfLevel;
            this.Will.MiscMod = playerCharacter.Will.MiscMod;
            this.Will.MiscMod2 = playerCharacter.Will.MiscMod2;
            this.Will.Name = playerCharacter.Will.Name;
            #endregion
            #region Wisdom
            this.Wisdom.Name = playerCharacter.Wisdom.Name;
            this.Wisdom.Score = playerCharacter.Wisdom.Score;
            #endregion
            this.XP = playerCharacter.XP;
            this.ImageName = playerCharacter.ImageName;
            this.Location = playerCharacter.Location;
            this.Rotation = playerCharacter.Rotation;
        }
        public void AlignmentFromString(string Alignment)
        {
            switch(Alignment)
            {
                case "Chaotic Evil":
                    this.Alignment = Alignments.Chaotic_Evil;
                    break;
                case "Evil":
                    this.Alignment = Alignments.Evil;
                    break;
                case "Good":
                    this.Alignment = Alignments.Good;
                    break;
                case "Lawful Good":
                    this.Alignment = Alignments.Lawful_Good;
                    break;
                default:
                    this.Alignment = Alignments.Unaligned;
                    break;
            }
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("Player Name   : {0}\r\n", PlayerName);
            sb.AppendFormat("Character Name: {0}\r\n", CharacterName);
            sb.AppendFormat("Level         : {0}\r\n", PlayerName);
            sb.AppendFormat("Class         : {0}\r\n", PlayerName);
            sb.AppendFormat("Paragon Path  : {0}\r\n", PlayerName);
            sb.AppendFormat("Epic Destiny  : {0}\r\n", PlayerName);
            sb.AppendFormat("Total XP      : {0}\r\n", PlayerName);
            sb.AppendFormat("Race          : {0}\r\n", PlayerName);
            sb.AppendFormat("Size          : {0}\r\n", PlayerName);
            sb.AppendFormat("Age           : {0}\r\n", PlayerName);
            sb.AppendFormat("Gender        : {0}\r\n", PlayerName);
            sb.AppendFormat("Height        : {0}\r\n", PlayerName);
            sb.AppendFormat("Weight        : {0}\r\n", PlayerName);
            sb.AppendFormat("Adventuring Company or Other Affiliations: {0}\r\n", PlayerName);
            sb.AppendFormat("Initiative    : {0}\tDEX:{1}\t1/2 Level:{2}\tMisc:{3}\r\nConditional Modifiers:{4}\r\n",
                Initiative, Dexterity.Modifier, (Level / 2), InitiativeMiscMod, InitiativeConditionalMods);
            sb.AppendFormat("{0}: {1}\tAbility Modifier:{2}\tAbility Modifier + 1/2 Level:{3}\r\n", 
                Strength.DisplayName, Strength.Score, Strength.Modifier, Strength.ModPlusOneHalfLevel(Level));
            sb.AppendFormat("{0}: {1}\tAbility Modifier:{2}\tAbility Modifier + 1/2 Level:{3}\r\n", 
                Constitution.DisplayName, Constitution.Score, Constitution.Modifier, Constitution.ModPlusOneHalfLevel(Level));
            sb.AppendFormat("{0}: {1}\tAbility Modifier:{2}\tAbility Modifier + 1/2 Level:{3}\r\n", 
                Dexterity.DisplayName, Dexterity.Score, Dexterity.Modifier, Dexterity.ModPlusOneHalfLevel(Level));
            sb.AppendFormat("{0}: {1}\tAbility Modifier:{2}\tAbility Modifier + 1/2 Level:{3}\r\n", 
                Intelligence.DisplayName, Intelligence.Score, Intelligence.Modifier, Intelligence.ModPlusOneHalfLevel(Level));
            sb.AppendFormat("{0}: {1}\tAbility Modifier:{2}\tAbility Modifier + 1/2 Level:{3}\r\n", 
                Wisdom.DisplayName, Wisdom.Score, Wisdom.Modifier, Wisdom.ModPlusOneHalfLevel(Level));
            sb.AppendFormat("{0}: {1}\tAbility Modifier:{2}\tAbility Modifier + 1/2 Level:{3}\r\n", 
                Charisma.DisplayName, Charisma.Score, Charisma.Modifier, Charisma.ModPlusOneHalfLevel(Level));
            return sb.ToString();
        }
        void Wisdom_OnAbilityScoreChanged(string Name)
        {
            throw new NotImplementedException();
        }

        void Intelligence_OnAbilityScoreChanged(string Name)
        {
            throw new NotImplementedException();
        }

        void Dexterity_OnAbilityScoreChanged(string Name)
        {
            throw new NotImplementedException();
        }

        void Constitution_OnAbilityScoreChanged(string Name)
        {
            throw new NotImplementedException();
        }

        void Strength_OnAbilityScoreChanged(string Name)
        {
            throw new NotImplementedException();
        }
        public void ResetToDefaults()
        {
            Strength = new AbilityScore("Strength");
            Constitution = new AbilityScore("Constitution");
            Dexterity = new AbilityScore("Dexterity");
            Intelligence = new AbilityScore("Intelligence");
            Wisdom = new AbilityScore("Wisdom");
            Charisma = new AbilityScore("Charisma");

            Acrobatics = new Skill("Acrobatics");
            Arcana = new Skill("Arcana");
            Athletics = new Skill("Athletics");
            Bluff = new Skill("Bluff");
            Diplomacy = new Skill("Diplomacy");
            Dungeoneering = new Skill("Dungeoneering");
            Endurance = new Skill("Endurance");
            Heal = new Skill("Heal");
            History = new Skill("History");
            Insight = new Skill("Insight");
            Intimidate = new Skill("Intimidate");
            Nature = new Skill("Nature");
            Perception = new Skill("Perception");
            Religion = new Skill("Religion");
            Stealth = new Skill("Stealth");
            Streetwise = new Skill("Streetwise");
            Thievery = new Skill("Thievery");

            ArmorClass = new Defense("Armor Class", "AC");
            Fortitude = new Defense("Fortitude", "FORT");
            Reflex = new Defense("Reflex", "REF");
            Will = new Defense("Will", "WILL");
            
        }
        public Counter GetCounter()
        {
            Counter c = new Counter();
            c.CounterID = "";
            c.IDLocation = new Point();
            c.ImageName = this.ImageName;
            c.Location = this.Location;
            c.Name = this.CharacterName;
            c.PlayerID = this.PlayerID;
            c.Rotation = 0;
            c.Size = new Size(1, 1);
            c.VisibleToPlayers = true;
            return c;
        }
       
    }
    public class AbilityScore
    {
        public delegate void AbilityScoreChangedEventHandler(string Name);
        public event AbilityScoreChangedEventHandler OnAbilityScoreChanged;
        public string Name;
        public string DisplayName
        {
            get
            {
                return Name.Substring(0, 3).ToUpper();
            }
        }
        private int _Score;
        public int Score
        {
            get
            {
                return _Score;
            }
            set
            {
                _Score = value;
                if (OnAbilityScoreChanged != null)
                {
                    OnAbilityScoreChanged(Name);
                }
            }
        }
        public int Modifier
        {
            get
            {
                if (Score > 1)
                {
                    return (Score / 2) - 5;
                }
                return -5;
            }
        }
        public int ModPlusOneHalfLevel(int Level)
        {
            return Modifier + (Level / 2);
        }
        public AbilityScore()
        {
        }
        public AbilityScore(string Name)
        {
            this.Name = Name;
        }
    }
    public class Skill
    {
        public string Name;
        public int Bonus
        {
            get
            {
                int s = ModPlusHalfLevel;
                if (Trained)
                {
                    s += 5;
                }
                s += ArmorPenalty;
                s += Misc;
                return s;
            }
        }
        public int ModPlusHalfLevel;
        public bool Trained;
        public int ArmorPenalty;
        public int Misc;
        public Skill()
        {
        }
        public Skill(string Name)
        {
            this.Name = Name;
        }
    }
    public class Defense
    {
        public string Name;
        public string DisplayName;
        public int Score
        {
            get
            {
                return 10 + HalfLevel + ArmorSlashAbilityMod + ClassMod + FeatMod + EnhancementMod + MiscMod + MiscMod2;
            }
        }
        public int HalfLevel;
        public int ArmorSlashAbilityMod;
        public int ClassMod;
        public int FeatMod;
        public int EnhancementMod;
        public int MiscMod;
        public int MiscMod2;
        public string ConditionalBonuses;
        public Defense()
        {
        }
        public Defense(string Name, string DisplayName)
        {
            this.Name = Name;
            this.DisplayName = DisplayName;
            HalfLevel = 0;
            ArmorSlashAbilityMod = 0;
            ClassMod = 0;
            FeatMod = 0;
            EnhancementMod = 0;
            MiscMod = 0;
            MiscMod2 = 0;
        }


    }
}
